#!/usr/bin/env python
"""

   count_while.py


   Copyright (C) 2007 Leo Goodstadt

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License
   as published by the Free Software Foundation; version 2
   of the License

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
"""



import sys
from general_util import die_error



def count_while(i):
   cnt = 0
   try:
     while(i.next()):
       cnt += 1
   except StopIteration:
     pass
   return cnt



#prints 3


def unit_test():
    search_text =  '    sfsdf'
    cnt_spaces = count_while(x ==' ' for x in search_text)
    print "%d leader spaces in '%s'" % (cnt_spaces, search_text)

    N_terminated_sequence = "ACACACACACNNNNNNNNNNNNNN"
    cnt_Ns = count_while(x =='N' for x in reversed(N_terminated_sequence))
    print "%d terminal 'N's in '%s'" % (cnt_Ns, N_terminated_sequence)
                
if __name__ == '__main__':
    unit_test()
    

